package com.example.im.bean;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.example.common.utils.SPUtils;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

/**
 * 消息 bean
 */
public class MessageBean implements MultiItemEntity {

    public static final int LAYOUT_OWN = 1;
    public static final int LAYOUT_OTHER = 2;

    public static final int STATUS_SENDING = 1;
    public static final int STATUS_SEND_FAILURE = 2;
    public static final int STATUS_SEND_SUCCESS = 3;
    public static final int STATUS_AS_READ = 4;
    public static final int STATUS_AS_UNREAD = 5;

    public int itemType;

    /**
     * 发送者 ID
     */
    private String senderId;

    /**
     * 备注名
     */
    private String remarksName;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 头像
     */
    private String headPhoto;

    /**
     * 消息时间
     */
    private long sendTime;

    /**
     * 消息类型
     */
    private int messageType;

    /**
     * 文本消息
     */
    private String textMessage;

    /**
     * 图片消息
     */
    private String imgMessage;

    /**
     * 自定义消息
     */
    private byte[] customMessage;

    /**
     * 消息状态
     */
    private int status;


    public String getSenderId() {
        return senderId;
    }

    public void setSenderId(String senderId) {
        this.senderId = senderId;
        this.itemType=senderId.equals(SPUtils.getInstance().getStringValue(SPUtils.IM_LOGIN)) ? LAYOUT_OWN : LAYOUT_OTHER;
    }

    public String getRemarksName() {
        return remarksName;
    }

    public void setRemarksName(String remarksName) {
        this.remarksName = remarksName;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getHeadPhoto() {
        return headPhoto;
    }

    public void setHeadPhoto(String headPhoto) {
        this.headPhoto = headPhoto;
    }

    public long getSendTime() {
        return sendTime;
    }

    public void setSendTime(long sendTime) {
        this.sendTime = sendTime;
    }

    public int getMessageType() {
        return messageType;
    }

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public String getTextMessage() {
        return textMessage;
    }

    public void setTextMessage(String textMessage) {
        this.textMessage = textMessage;
    }

    public String getImgMessage() {
        return imgMessage;
    }

    public void setImgMessage(String imgMessage) {
        this.imgMessage = imgMessage;
    }

    public byte[] getCustomMessage() {
        return customMessage;
    }

    public void setCustomMessage(byte[] customMessage) {
        this.customMessage = customMessage;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }

    public MessageBean() {

    }

    /**
     * @param senderId      发送者 ID
     * @param remarksName   备注名
     * @param nickName      昵称
     * @param headPhoto     头像
     * @param sendTime      发送时间
     * @param messageType   消息类型
     * @param textMessage   文本消息
     * @param imgMessage    图片消息
     * @param customMessage 自定义消息
     */
    public MessageBean(String senderId, String remarksName, String nickName, String headPhoto, long sendTime, int messageType, String textMessage, String imgMessage, byte[] customMessage) {
        this.senderId = senderId;
        this.remarksName = remarksName;
        this.nickName = nickName;
        this.headPhoto = headPhoto;
        this.sendTime = sendTime;
        this.messageType = messageType;
        this.textMessage = textMessage;
        this.imgMessage = imgMessage;
        this.customMessage = customMessage;
        this.itemType = senderId.equals(SPUtils.getInstance().getStringValue(SPUtils.IM_LOGIN)) ? LAYOUT_OWN : LAYOUT_OTHER;
    }

    @NotNull
    @Override
    public String toString() {
        return "MessageBean{" +
                "senderId='" + senderId + '\'' +
                ", remarksName='" + remarksName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", headPhoto='" + headPhoto + '\'' +
                ", sendTime=" + sendTime +
                ", messageType=" + messageType +
                ", textMessage='" + textMessage + '\'' +
                ", imgMessage='" + imgMessage + '\'' +
                ", customMessage=" + Arrays.toString(customMessage) +
                '}';
    }
}
